//
//  BC_GameTreeController.h
//  GameTree
//
//  Created by BrunoCausse on 13/11/10.
//  Copyright 2010-2013 poulailler cie. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#import "BC_Browser.h"

@class CocOthAppController;

@class BC_BrowserTreeNode;
@class BC_Game;
@class BC_Browser;
@class BC_Move;
@class BC_ZooRequest;

extern NSString * const BCBrowerKey;
extern NSString * const BCRootKey;


@interface BC_GameTreeController : NSWindowController <BC_BrowserDelegate> {
	
	IBOutlet CocOthAppController	*appController;

	//UI principal
	
	IBOutlet BC_Browser				*browser;
	IBOutlet NSBox					*boxInfos;
	IBOutlet NSTextField			*scoreField;
	IBOutlet NSTextField			*timeField;
	IBOutlet NSTextView				*commentField;
	IBOutlet NSButton				*solveButton;
	IBOutlet NSProgressIndicator	*progressIndicator;
	
	
	NSArray							*imagettes;
	
	//UI tag game
	IBOutlet NSWindow				*tagsGameSheet;
	
	IBOutlet NSTextField			*eventField;
	IBOutlet NSTextField			*siteField;
	IBOutlet NSTextField			*roundField;
	IBOutlet NSTextField			*dateField;
	IBOutlet NSTextField			*blackField;
	IBOutlet NSTextField			*whiteField;
	IBOutlet NSTextField			*resultField;
	

	// le modele
	BC_Game							*game;

	NSTreeNode						*root;
	NSTreeNode						*currentNode;
	
	//Drag&Drop
	NSIndexSet						*draggedIndexSet;
	NSInteger						draggedColumn; 

					
}


#pragma mark utilities

- (NSTreeNode *)representedParentForColumn:(NSInteger)column;
- (id)nodeAtIndexPath:(NSIndexPath *)indexPath;

- (void)selectionDidChange:(id)sender;
- (void)updateInfoBox:(NSTreeNode *)node;
- (void)displayInfoBox:(NSTreeNode *)node;


#pragma mark Changing Model

- (void)addVariation:(NSArray *)moves;
- (void)addMove:(BC_Move *)move;

- (void)addPrincipalVariationFromZoo:(BC_ZooRequest *)aRequest;
- (void)addOtherVariationFromZoo:(BC_ZooRequest *)aRequest;

- (void)removeVariation:(int)sq;

- (void)addMoveAndPlay:(BC_Move *)move;

- (void)removeNode:(BC_BrowserTreeNode *)node atIndexPath:(NSIndexPath *)indexPath;

- (void)tryParseString:(NSString *)pString;
- (BOOL)tryParseStringFromScript:(NSString *)pString;

- (void)setCurrentScore:(float)s;
- (void)setCurrentTime:(float)t;

#pragma mark information

- (NSString *)nameVariation:(int)sq;
- (NSString *)scoreVariation:(int)sq;

- (void)setTag:(int)tag atVariation:(int)sq;
- (int)tagAtSquare:(int)sq;

- (NSString *)descriptionPVariation;

#pragma mark navigation

- (BOOL)forward;
- (BOOL)backstep;

- (void)manageMenu:(NSTreeNode *)node;

//protocol BC_BrowserDelegate
- (BOOL)browserForward:(NSBrowser *)theBrowser;

#pragma mark un/archiving methods

- (NSDictionary *)propertyList;
- (void)setRootWithPropertyList:(NSURL *)url;

#pragma mark Actions

- (IBAction)rootPosition:(id)sender;
- (IBAction)endVariation:(id)sender;

- (IBAction)editTagsGame:(id)sender;
- (IBAction)tagsGameButton:(id)sender;

#pragma mark progressIndicator

- (void)setEnabledSolveButton:(BOOL)enabled;

- (void)startAnimation;
- (void)stopAnimation;


@end
